/**
 * xmlloader.h is part of Gedule.
 *
 * Gedule is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gedule is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Gedule.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef XMLLOADER_H
#define XMLLOADER_H

#include "loader.h"
#include <string>
#include <QXmlStreamReader>

// Forward declarations.
class Task;
class Resource;
class Unavailabilities;

class XmlLoader : public Loader
{
public:

    XmlLoader( const std::string & a_file );

    virtual ~XmlLoader() {}

    virtual bool Load( Model & a_model );

private:

    // Fields.
    // -------

    std::string         m_file;
    QXmlStreamReader    m_xmlStream;

    // Methods.
    // --------

    // Protect default constructor.
    XmlLoader();

    // Protect copy constructor.
    XmlLoader( const XmlLoader & a_other );

    // Protect operator =.
    XmlLoader & operator = ( const XmlLoader & a_other );

    void ReadElement(QXmlStreamReader::TokenType a_type, QXmlStreamReader & a_xmlStream, Model & a_model );
    void ReadModel( QXmlStreamReader & a_xmlStream, Model & a_model );
    void ReadTask       (QXmlStreamReader & a_xmlStream, Model & a_model );
    void ReadResource   ( QXmlStreamReader & a_xmlStream, Model & a_model );
    void ReadModelConstraint ( QXmlStreamReader & a_xmlStream, Model & a_model );
    void ReadAllowIdleConstraint( QXmlStreamReader & a_xmlStream, Model & a_model );
    void ReadMaxTimeConstraint  ( QXmlStreamReader & a_xmlStream, Model & a_model );
    void ReadPrecedenceConstraint( QXmlStreamReader & a_xmlStream, Model & a_model );
    void ReadTaskConstraints( QXmlStreamReader & a_xmlStream, Task * a_task );
    void ReadTaskConstraint ( QXmlStreamReader & a_xmlStream, Task * a_task);
    void ReadTimeWindowConstraint( QXmlStreamReader & a_xmlStream, Task * a_task );
    void ReadLenghtConstraint    ( QXmlStreamReader & a_xmlStream, Task * a_task );
    void ReadResourcesNeededConstraint ( QXmlStreamReader & a_xmlStream, Task * a_task );
    void ReadResourceConstraints ( QXmlStreamReader & a_xmlStream, Resource * a_resource );
    void ReadResourceConstraint  ( QXmlStreamReader & a_xmlStream, Resource * a_resource );
    void ReadCapacityConstraint( QXmlStreamReader & a_xmlStream, Resource * a_resource );
    void ReadUnavailabilitiesConstraint( QXmlStreamReader & a_xmlStream, Resource * a_resource );
    void ReadUnavailability( QXmlStreamReader & a_xmlStream, Unavailabilities * a_constraint );

    void HandleError( QXmlStreamReader & a_xmlStream );

    bool IsStartElement( QXmlStreamReader::TokenType a_type );
    bool IsEndElement( QXmlStreamReader::TokenType a_type );
};

#endif // XMLLOADER_H
